/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fanor.sessionbeans;

import br.edu.fanor.entidades.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Casa
 */
@Stateless
public class LoginService{
    
    @PersistenceContext(unitName = "LocadoraVideoWebPU")
    private EntityManager manager;
    
    public boolean verificaUsuario(Usuario usuario){
        boolean retorno = false;
        long cont = 0;
        
        Query query = manager.createQuery("SELECT count(u) FROM Usuario u "
                +"WHERE u.nome = '"+usuario.getNome()+"' and u.senha ='"+usuario.getSenha()+"'");
        Object result = (Object) query.getSingleResult();
        cont = (Long) result;
        
        if(cont != 0){
            retorno = true;
        }
        
        return retorno;
    }
    
}
